package com.mail.server.controller;


import com.mail.model.db.SmsFlashPromotion;
import com.mail.server.common.R;
import com.mail.server.service.SmsFlashPromotionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 限时购表 前端控制器
 * </p>
 *
 * @author yan
 * @since 2022-06-20
 */
@RestController
@RequestMapping("/flash")
public class SmsFlashPromotionController {
    @Autowired
    private SmsFlashPromotionService service;

    @PostMapping("create")
    public R create(@RequestBody SmsFlashPromotion smsFlashPromotion) {
        return service.create(smsFlashPromotion);
    }

    @PostMapping("/delete/{id}")
    public R delete(@PathVariable Long id) {
        return service.delete(id);
    }

    /**
     * 根据活动名称分页查询
     *
     * @param keyword
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/list")
    public R list(@RequestParam(value = "keyword", required = false) String keyword, @RequestParam(defaultValue = "1") Long pageNum,
                  @RequestParam(defaultValue = "10") Long pageSize) {
        return service.list(keyword, pageNum, pageSize);
    }

    /**
     * 修改上下线状态
     *
     * @param id
     * @param status
     * @return
     */
    @PostMapping("update/status/{id}")
    public R updateStatus(@PathVariable Long id,
                          @RequestParam(value = "status", required = false) Integer status) {
        return service.updateStatus(id, status);
    }

    /**
     * @param id
     * @param promotion
     * @return
     */
    @PostMapping("update/{id}")
    public R updateFlashPromotion(@PathVariable Long id, @RequestBody SmsFlashPromotion promotion) {
        return service.updateFlashPromotion(id, promotion);
    }

    @GetMapping("/{id}")
    public R getFlashPromotion(@PathVariable Long id) {
        return service.getFlashPromotion(id);
    }
}
